# 自定义异常类:
class LenError(Exception):
    def __str__(self):
        # 异常描述信息
        return '输入的长度不合法'

# 语法:
# 抛出异常
# raise 类名()
user_name = input('user_name:')
try:
    if (len(user_name) >= 6) and (len(user_name) <= 12):
        print('输入的数据合法')
    else:
        raise LenError()
except LenError as e:
    print(e)